package org.zhq;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * @author zhengquan
 * @date 2019/2/7
 */
public class Foo {

    //绑定Stream到一个命令连接(带参数)
    public static final String COMMAND_CONNECTOR_BIND = "--m c bind ";
    //创建对话房间
    public static final String COMMAND_AUDIO_CREATE_ROOM = "--m a create";
    //加入对话房间(带参数)
    public static final String COMMAND_AUDIO_JOIN_ROOM = "--m a join ";
    //主动离开对话房间
    public static final String COMMAND_AUDIO_LEAVE_ROOM = "--m a leave";

    //回送服务器上的唯一标示(带参数)
    public static final String COMMAND_INFO_NAME = "--i server ";
    //回送语音房间号(带参数)
    public static final String COMMAND_INFO_AUDIO_ROOM = "--i a room ";
    //回送语音开始(带参数)
    public static final String COMMAND_INFO_AUDIO_START = "--i a start ";
    //回送语音结束(带参数)
    public static final String COMMAND_INFO_AUDIO_STOP = "--i a stop";
    //回送语音操作错误
    public static final String COMMAND_INFO_AUDIO_ERROR = "--i a error";

    //群操作前缀
    public static final String COMMAND_GROUP_PREFIX = "--m g ";
    //加入群
    public static final String COMMAND_GROUP_JOIN = "join";
    //退出群
    public static final String COMMAND_GROUP_LEAVE = "leave";
    //创建群
    public static final String COMMAND_GROUP_CREATE = "create";
    //给群发送信息
    public static final String COMMAND_GROUP_SEND = "send";

    private static final String CACHE_DIR = "cache";

    public static final String COMMAND_EXIT = "00bye00";
    
    public static final String COMMAND_HELP = "[操作指南]\r\n" +
            "创建群 --m g create [群名]\r\n" +
            "加入群 --m g join [群名]\r\n" +
            "退出群 --m g leave [群名]\r\n" +
            "群发信息 --m g send [群名] [信息体]";

    /**
     * 创建一个文件夹
     *
     * @param dir
     * @return
     */
    public static File getCacheDir(String dir) {
        String path = System.getProperty("user.dir") + File.separator + CACHE_DIR + File.separator + dir;
        File file = new File(path);

        if (!file.exists()) {
            if (!file.mkdirs()) {
                throw new RuntimeException("创建文件失败,路径:" + path);
            }
        }
        return file;
    }

    /**
     * 创建一个临时的随机文件
     *
     * @param parent
     * @return
     */
    public static File createRandomTemp(File parent) {
        String fileName = UUID.randomUUID().toString() + ".tmp";
        File file = new File(parent, fileName);
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return file;
    }

}
